package com.yyfax.pay.order.model.to;

import org.apache.commons.lang3.StringUtils;

import com.yyfax.framework.exception.YYException;
import com.yyfax.framework.yyfax.enums.RspCodeEnum;
import com.yyfax.framework.yyfax.enums.TerminalEnum;
import com.yyfax.pay.common.model.to.YYPayParams;

/**
 * 独立鉴权form请求参数
 * 
 * @author buyi
 * @date 2017-04-15 16:26:40
 * @since v1.0.0
 */
@SuppressWarnings("serial")
public class AuthOrderParams extends YYPayParams {
	private String userIp; // 用户端请求IP
	private String serverIp; // 服务器请求Ip
	private String merchantCode; // 商户编号
	private String userId; // 商户用户ID
	private String terminal;
	private String orderId;
	private String orderTime;
	private String expireTime;
	private String paymentCode;
	private String returnUrl;
	private String notifyUrl;
	private String idNo;
	private String name;
	private String cardNo;

	public String getUserIp() {
		return userIp;
	}

	public void setUserIp(String userIp) {
		this.userIp = userIp;
	}

	public String getServerIp() {
		return serverIp;
	}

	public void setServerIp(String serverIp) {
		this.serverIp = serverIp;
	}

	public String getMerchantCode() {
		return merchantCode;
	}

	public void setMerchantCode(String merchantCode) {
		this.merchantCode = merchantCode;
	}

	public String getUserId() {
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}

	public String getTerminal() {
		return terminal;
	}

	public void setTerminal(String terminal) {
		this.terminal = terminal;
	}

	public String getOrderId() {
		return orderId;
	}

	public void setOrderId(String orderId) {
		this.orderId = orderId;
	}

	public String getOrderTime() {
		return orderTime;
	}

	public void setOrderTime(String orderTime) {
		this.orderTime = orderTime;
	}

	public String getExpireTime() {
		return expireTime;
	}

	public void setExpireTime(String expireTime) {
		this.expireTime = expireTime;
	}

	public String getPaymentCode() {
		return paymentCode;
	}

	public void setPaymentCode(String paymentCode) {
		this.paymentCode = paymentCode;
	}

	public String getReturnUrl() {
		return returnUrl;
	}

	public void setReturnUrl(String returnUrl) {
		this.returnUrl = returnUrl;
	}

	public String getNotifyUrl() {
		return notifyUrl;
	}

	public void setNotifyUrl(String notifyUrl) {
		this.notifyUrl = notifyUrl;
	}

	public String getIdNo() {
		return idNo;
	}

	public void setIdNo(String idNo) {
		this.idNo = idNo;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getCardNo() {
		return cardNo;
	}

	public void setCardNo(String cardNo) {
		this.cardNo = cardNo;
	}

	@Override
	public boolean validate() throws Exception {
		if (StringUtils.isBlank(this.userIp)) {
			throw new YYException(RspCodeEnum.COMMON_ERROR_PARAMETER_INVALID, "参数 'userIp'不能为空");
		}

		if (StringUtils.isBlank(this.serverIp)) {
			throw new YYException(RspCodeEnum.COMMON_ERROR_PARAMETER_INVALID, "参数 'serverIp'不能为空");
		}

		if (StringUtils.isBlank(this.merchantCode)) {
			throw new YYException(RspCodeEnum.COMMON_ERROR_PARAMETER_INVALID, "参数 'merchantCode'不能为空");
		}

		if (StringUtils.isBlank(this.userId)) {
			throw new YYException(RspCodeEnum.COMMON_ERROR_PARAMETER_INVALID, "参数 'userId'不能为空");
		}

		if (StringUtils.isBlank(this.orderId)) {
			throw new YYException(RspCodeEnum.COMMON_ERROR_PARAMETER_INVALID, "参数 'orderId'不能为空");
		}

		if (StringUtils.isBlank(this.orderTime)) {
			throw new YYException(RspCodeEnum.COMMON_ERROR_PARAMETER_INVALID, "参数 'orderTime'不能为空");
		}

		if (StringUtils.isBlank(this.terminal) && !TerminalEnum.PC.isValue(this.terminal) && !TerminalEnum.H5.isValue(this.terminal)) {
			throw new YYException(RspCodeEnum.COMMON_ERROR_PARAMETER_INVALID, "参数 'terminal'不能为空，或者不支持的终端类型");
		}

		if (StringUtils.isBlank(this.returnUrl)) {
			throw new YYException(RspCodeEnum.COMMON_ERROR_PARAMETER_INVALID, "参数 'returnUrl'不能为空");
		}

		if (StringUtils.isBlank(this.notifyUrl)) {
			throw new YYException(RspCodeEnum.COMMON_ERROR_PARAMETER_INVALID, "参数 'notifyUrl'不能为空");
		}

		return true;
	}

	@Override
	public String[] signFields() {
		return new String[] { "userIp", "serverIp", "merchantCode", "userId", "terminal", "orderId", "orderTime", "expireTime", "paymentCode",
				"returnUrl", "notifyUrl" };
	}

}
